﻿using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using ALDIOrganizer.Properties;
using Generator;

namespace ALDIOrganizer
{
    public partial class MainForm
    {
        private void CurrentTemplate_OnModifiedChanged(bool pNewValue)
        {
            btnSaveTemplate.Enabled = pNewValue;
            if (!pNewValue)
            {
                svTemplate.Focus();
                return;
            }
            if(Program.CurrentFile.IsTemplateExclusivelyMine(
                CurrentTemplate.Name,
                CurrentRota))
            {
                return;
            }
            WhenTemplateIsModified(
                CurrentRota,
                CurrentTemplate);
        }

        private void CurrentTemplate_OnWorkingHoursUpdated(WorkingHoursSpan[] pNewHours, Weekday[] pDays)
        {
            foreach (var day in pDays)
            {
                CurrentRota.SetWorkingHours(
                    pNewHours[day.ToInt0()],
                    day);
                CurrentRota.RefreshColumn(day);
            }
            svRota.TotalRefresh(pDays);
            svTemplate.TotalRefresh(pDays);
        }
    }
}
